<template>
  <el-container class="homecontainer">
    <!-- 头部 -->
    <el-header>
      <div>
        <img src="../assets/logo.png" />
        <span>后台管理系统</span>
      </div>
      <el-button @click="tuichu" type="info">退出</el-button>
    </el-header>
    <el-container>
      <!-- 侧边 -->
      <el-aside :width="zhe ? '64px' : '200px'">
        <div class="zhedie" @click="zhedieclk">|||</div>
        <el-menu
          :default-active="dangqian"
          router
          :collapse-transition="false"
          :collapse="zhe"
          unique-opened
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          ><!-- 一级菜单 -->
          <el-submenu
            :index="item.id + ' '"
            v-for="item in liebiao"
            :key="item.id"
          >
            <!-- 模板 -->
            <template slot="title">
              <!-- 图标 -->
              <!-- 使用循环出来的id作为索引动态绑定图标 -->
              <i :class="tubiao[item.id]"></i>
              <!-- 文字 -->
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
              @click="dangqianindex('/' + items.path)"
              :index="'/' + items.path"
              v-for="items in item.children"
              :key="items.id"
              ><template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ items.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 内容 -->
      <el-main><router-view></router-view></el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "Home",
  created() {
    this.caidan();
    this.dangqian=window.sessionStorage.getItem('dangqian')
  },
  data() {
    return {
      zhe: false,
      dangqian: "",
      liebiao: [],
      tubiao: {
        125: "iconfont icon-yonghu",
        103: "iconfont icon-ziyuan112",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-dingdan",
        145: "iconfont icon-weibiaoti--",
      },
    };
  },
  methods: {
    tuichu() {
      window.sessionStorage.clear();
      this.$router.push("/Login");
    },
    dangqianindex(index){
      window.sessionStorage.setItem('dangqian',index)
      this.dangqian=index
    },
    async caidan() {
      const { data: res } = await this.$http.get("menus");
     /*  console.log(res); */
      if (res.meta.status != 200) return this.$message.error(res.meta.msg);
      this.liebiao = res.data;
     /*  console.log(this.liebiao); */
    },
    zhedieclk() {
      this.zhe = !this.zhe;
    },
  },
};
</script>

<style lang="less" scoped>
.homecontainer {
  height: 100%;
}
.iconfont {
  margin: 0 10px;
}
.zhedie {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #ffffff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.el-header {
  background-color: #373d41;

  display: flex;
  justify-content: space-between;
  align-items: center;
  div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    img {
      height: 60px;
    }
    span {
      font-size: 30px;
      color: #ffffff;
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #333744;
}
.el-main {
  background-color: #eaedf1;
}
.el-menu {
  border: none;
}
</style>